from django.core.management.base import BaseCommand
from search.sync.binlog_sync import BinlogSync

class Command(BaseCommand):
    help = 'Start MySQL binlog sync to Elasticsearch'

    def handle(self, *args, **options):
        self.stdout.write('Starting binlog sync...')
        try:
            sync = BinlogSync()
            sync.start_sync()
        except KeyboardInterrupt:
            self.stdout.write(self.style.SUCCESS('Binlog sync stopped'))
        except Exception as e:
            self.stdout.write(self.style.ERROR(f'Error: {str(e)}'))